/*
 * Copyright 2012 NJUT  qixiaobo. All rights reserved.
 */
package com.fujitsu.nanjing.tieba.view.velocity.tools;

import org.apache.velocity.tools.config.DefaultKey;
import org.apache.velocity.tools.generic.SafeConfig;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Scope;

import com.fujitsu.nanjing.tieba.service.GroupService;

/**
 * GroupTool.java
 * <p>
 * 提供组别的显示文字
 * </p>
 * 
 * @author Qixiaobo-win8
 */

@Configurable("groupTool")
@DefaultKey("group")
@Scope
@DependsOn
public class GroupTool extends SafeConfig {
	private GroupService groupService;
	public String groupName(String groupId) {
		if (groupId == null || groupId.trim().equals("")) {
			return "无名组";
		}
		return getGroupService().findById(groupId).getGroupname();
	}
	public void setGroupService(GroupService groupService) {
		this.groupService = groupService;
	}
	public GroupService getGroupService() {
		return groupService;
	}
	public int stars(String groupId) {
		if (groupId == null || groupId.trim().equals("")) {
			return 0;
		}
		return getGroupService().findById(groupId).getStars();
	}
	/**
	 * 判断是否拥有权限
	 * */
	public String right(String rightType, String rights) {
		if (rights.indexOf(rightType) == -1) {
			return "F";
		}
		return "T";
	}
}
